package com.example.easy.Controller;


import com.example.easy.Dto.MessageBoard;
import com.example.easy.Dto.Notice;
import com.example.easy.Service.myservice.MessageBoardServise;
import com.example.easy.Service.myservice.NoticeServise;
import com.example.easy.Tools.ResultCode;
import com.example.easy.mapper.MessageBoardMapper;
import com.example.easy.mapper.NoticeMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Scope("prototype")
@RestController
@Api(value = "MessageBoard", description = "留言栏管理")
@RequestMapping(value = "/messageBoard")

public class MessageBoardController {


    @Autowired
    MessageBoardServise messageBoardServise;


    @Autowired
    MessageBoardMapper messageBoardMapper;

    @ApiOperation(value = "用户留言", notes = "用户留言")
    @RequestMapping(value = "/insMessageBoard", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object insMessageBoard(@RequestBody MessageBoard messageBoard) throws IOException {

        return ResultCode.SUCCESS.result(messageBoardMapper.insMessageBoard(messageBoard));

    }

    @ApiOperation(value = "回复", notes = "回复")
    @RequestMapping(value = "/reply", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object reply(@RequestBody MessageBoard messageBoard) throws IOException {

        return ResultCode.SUCCESS.result(messageBoardMapper.reply(messageBoard));

    }

    @ApiOperation(value = "查看个人留言", notes = "查看个人留言")
    @RequestMapping(value = "/select", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object select(@RequestBody String username) throws IOException {

        System.out.println(messageBoardMapper.select(username));

        return ResultCode.SUCCESS.result(messageBoardMapper.select(username));

    }

    @ApiOperation(value = "查看未背回复的留言", notes = "查看未背回复的留言")
    @RequestMapping(value = "/selectreply", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object selectreply() throws IOException {

        return ResultCode.SUCCESS.result(messageBoardMapper.selectreply());

    }

    @ApiOperation(value = "查看所有留言", notes = "查看所有留言")
    @RequestMapping(value = "/selectall", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object selectall() throws IOException {

        return ResultCode.SUCCESS.result(messageBoardMapper.selectall());

    }

}
